package com.ls.lserp.modules.produce.service;

import com.ls.lserp.common.service.CrudService;
import com.ls.lserp.dbaccess.Entity.OrderEntity;
import com.ls.lserp.modules.produce.dao.PrinterForSfDao;
import com.ls.lserp.modules.produce.dao.ProduceLossDao;
import com.ls.lserp.modules.produce.entity.PrinterForSfEntity;
import com.ls.lserp.modules.produce.entity.ProduceLoss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional(readOnly = false)
public class PrinterForSfService extends CrudService<ProduceLossDao,ProduceLoss> {

	@Autowired
    private PrinterForSfDao printerForSfDao;

		/**
		 * 查询用户详情
		 * @param printerForSfEntity
		 * @return
		 */
		public PrinterForSfEntity selectDataToXml(PrinterForSfEntity printerForSfEntity){
            PrinterForSfEntity py = printerForSfDao.selectDataToXml(printerForSfEntity.getBarCode());
            py.setCity(printerForSfDao.selectAddressCode(py));
            py.setCount(printerForSfDao.findCount(printerForSfEntity.getBarCode()));
			return py;
		}
        /**
         * 更新订单信息和更新顺丰运单号
         * @param maiNo
         * @param barCode
         */
		public List<OrderEntity> upDataAccounting(String maiNo,String barCode){
            printerForSfDao.updataAccountingMaiNo(maiNo,barCode);
            List<OrderEntity> list = printerForSfDao.selectOrderId(barCode);
            for(OrderEntity entity:list) {
                printerForSfDao.orderStatusCode(entity.getOrderId().toString());
            }

            return list;
        }
    /**
     * 更新订单信息和更新顺丰运单号
     * @param list
     */
    public void upDataOrder(List<OrderEntity> list){
        for(OrderEntity entity:list) {
            printerForSfDao.orderStatusCodeForErp(entity.getOrderNo());
        }
    }
}
